package com.example.smartcitymovie.ui.movie;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;

import com.example.smartcitymovie.MyApplication;
import com.example.smartcitymovie.R;
import com.example.smartcitymovie.adapter.RecycleViewAdapter;
import com.example.smartcitymovie.bean.MovieListBean;
import com.example.smartcitymovie.dataRepo.ApiData;
import com.example.smartcitymovie.databinding.ActivityMovieListBinding;
import com.example.smartcitymovie.utils.OkHttpUtils;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

public class MovieListActivity extends AppCompatActivity {

    ActivityMovieListBinding binding;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityMovieListBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        getSupportActionBar().setTitle("热播影片");
        initView();
    }

    private void initView() {
        loadRecommandMovie();
    }

    private void loadRecommandMovie() {
        MovieListBean movieListBean = ApiData.getMovieListBean();
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                binding.RVShowMovieList.setLinearLayoutManager(LinearLayout.VERTICAL);
                binding.RVShowMovieList.setAdapter(movieListBean.getRows(),R.layout.movie_list_item_layout_style_two);
                binding.RVShowMovieList.getBaseAdapter().setOnPartRecycleViewItemClickListener(new RecycleViewAdapter.OnPartRecycleViewItemClickListener() {
                    @Override
                    public void onPartRecycleViewItemClickListener(View view, int position) {
                        Intent intent = new Intent(MovieListActivity.this, MovieMessageActivity.class);
                        intent.putExtra("id",movieListBean.getRows().get(position).getId());
                        startActivity(intent);
                    }
                },R.id.btn_BuyMovie);
            }
        });
    }
}